package com.youlai.boot.system.controller;

import com.youlai.boot.system.service.LpsOrderYlService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.youlai.boot.system.model.form.LpsOrderYlForm;
import com.youlai.boot.system.model.query.LpsOrderYlQuery;
import com.youlai.boot.system.model.vo.LpsOrderYlVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;

/**
 * 永乐前端控制层
 *
 * @author lwb
 * @since 2025-07-18 14:54
 */
@Tag(name = "永乐接口")
@RestController
@RequestMapping("/api/v1/lpsOrderYls")
@RequiredArgsConstructor
public class LpsOrderYlController  {

    private final LpsOrderYlService lpsOrderYlService;

    @Operation(summary = "永乐分页列表")
    @GetMapping("/page")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderYl:query')")
    public PageResult<LpsOrderYlVO> getLpsOrderYlPage(LpsOrderYlQuery queryParams ) {
        IPage<LpsOrderYlVO> result = lpsOrderYlService.getLpsOrderYlPage(queryParams);
        return PageResult.success(result);
    }

    @Operation(summary = "新增永乐")
    @PostMapping
    @PreAuthorize("@ss.hasPerm('system:lpsOrderYl:add')")
    public Result<Void> saveLpsOrderYl(@RequestBody @Valid LpsOrderYlForm formData ) {
        boolean result = lpsOrderYlService.saveLpsOrderYl(formData);
        return Result.judge(result);
    }

    @Operation(summary = "获取永乐表单数据")
    @GetMapping("/{id}/form")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderYl:edit')")
    public Result<LpsOrderYlForm> getLpsOrderYlForm(
        @Parameter(description = "永乐ID") @PathVariable Long id
    ) {
        LpsOrderYlForm formData = lpsOrderYlService.getLpsOrderYlFormData(id);
        return Result.success(formData);
    }

    @Operation(summary = "修改永乐")
    @PutMapping(value = "/{id}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderYl:edit')")
    public Result<Void> updateLpsOrderYl(
            @Parameter(description = "永乐ID") @PathVariable Long id,
            @RequestBody @Validated LpsOrderYlForm formData
    ) {
        boolean result = lpsOrderYlService.updateLpsOrderYl(id, formData);
        return Result.judge(result);
    }

    @Operation(summary = "删除永乐")
    @DeleteMapping("/{ids}")
    @PreAuthorize("@ss.hasPerm('system:lpsOrderYl:delete')")
    public Result<Void> deleteLpsOrderYls(
        @Parameter(description = "永乐ID，多个以英文逗号(,)分割") @PathVariable String ids
    ) {
        boolean result = lpsOrderYlService.deleteLpsOrderYls(ids);
        return Result.judge(result);
    }
}
